package com.woniuxy.yogaapp.service.imp;

import com.woniuxy.yogaapp.dto.EvaluateDto;
import com.woniuxy.yogaapp.dto.UidDto;
import com.woniuxy.yogaapp.mapper.AppraiseMapper;
import com.woniuxy.yogaapp.mapper.CoachMapper;
import com.woniuxy.yogaapp.mapper.StudentMapper;
import com.woniuxy.yogaapp.mapper.UserMapper;
import com.woniuxy.yogaapp.pojo.Appraise;
import com.woniuxy.yogaapp.pojo.Coach;
import com.woniuxy.yogaapp.pojo.Student;
import com.woniuxy.yogaapp.service.AppraiseService;
import lombok.Data;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 *@author：源
 *@date:16:37:14
 *@descripion
 */
@Service
@Data
public class AppraiseServiceImp implements AppraiseService {
	@Resource
	private UserMapper userMapper;
	@Resource
	private AppraiseMapper appraiseMapper;
	@Resource
	private CoachMapper coachMapper;

	@Override
	public String evaluate(EvaluateDto evaluateDto) {
		evaluateDto.setAptime(new Date());
		// 1.通过两个id找到uid
		UidDto uidDto =userMapper.selectUidBycid(evaluateDto);

		evaluateDto.setAprec(uidDto.getUid());
		UidDto uidDto1=userMapper.selectUidBysid(evaluateDto);
		evaluateDto.setSnickname(uidDto1.getSnickname());
		evaluateDto.setApsender(uidDto1.getUid());
		// 2.存入评论表并返回一个apid
		appraiseMapper.insertApparise(evaluateDto);
		System.out.println("--------");
		System.out.println(evaluateDto);


		// 3.将apid插入detailore
		int i = appraiseMapper.insertApid(evaluateDto);
		if (i > 0) {
			return "评论插入成功";
		}

		return "失败";
	}

	// 查询某个教练的所有评论
	@Override
	public List<Appraise> showAppraise(Coach coach) {
		// 获取被评价人的uid
		int aprec = coach.getUid();
		// 查询被评价人的评价信息
		List<Appraise> app = appraiseMapper.findAppraise(aprec);
		return app;
	}

	@Override
	public String fixevaluate(EvaluateDto evaluateDto) {
		//通过apid找到并更改评论表
		int i=appraiseMapper.updateAppraise(evaluateDto);
		if(i>0){
			return "更新成功";
		}
		return "失败";
	}
}
